package study.dubbo.springboot.consumer.support.exception;

import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.rpc.RpcException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import study.eggs.result.Result;
import study.eggs.result.Results;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Throwable.class)
    public Result resolveException(Exception ex) {
        log.error("异常: ", ex);
        if (ex instanceof RpcException) {
            // rpc exception
            return Results.fail(888, "RPC调用异常");
        } else {
            // other exception
            return Results.fail();
        }
    }
}
